package JunitTests;
import java.util.ArrayList;

import junit.framework.TestCase;

import org.junit.Test;

import common.Calculations;

public class CalculationsTest extends TestCase{

	private Calculations calc;
	public CalculationsTest()
	{
		calc = new Calculations();
	}
	@Test
	public void testAverage() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		for (int i = 1; i <= 100; i++)
			grades.add(i);
		assertTrue(Calculations.average(grades).equals(new Float(50.5)));
		grades.add(0);
		assertTrue(Calculations.average(grades).equals(new Float(50)));
	}
	@Test
	public void testAverageEmpty() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		assertTrue(Calculations.average(grades).equals(new Float(0)));
	}
	@Test
	public void testMedian() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		for (int i = 1; i <= 100; i++)
			grades.add(i);
		assertTrue(Calculations.Median(grades).equals(new Float(50.5)));
		grades.add(100);
		assertTrue(Calculations.Median(grades).equals(new Float(51)));
	}
	@Test
	public void testMedianEmpty() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		assertTrue(Calculations.Median(grades).equals(new Float(0)));
	}
	@Test
	public void testDistributionAll10() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		int[] dis;
		for (int i = 1; i <= 100; i++)
			grades.add(i);
		dis = Calculations.distribution(grades);
		for (int i = 0; i < 10; i++)
			assertTrue(dis[i] == 10);
		
	}
	
	public void testDistribution() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		int[] dis;
		grades.add(10);
		
		grades.add(24);
		
		grades.add(36);
		grades.add(34);
		grades.add(38);
		grades.add(39);
		
		grades.add(45);
		
		grades.add(50);
		grades.add(55);
		grades.add(56);
		
		grades.add(78);
		grades.add(73);
		
		grades.add(85);
		grades.add(88);
		grades.add(89);
		
		dis = Calculations.distribution(grades);
		assertTrue(dis[0] == 1);
		assertTrue(dis[1] == 0);
		assertTrue(dis[2] == 1);
		assertTrue(dis[3] == 4);
		assertTrue(dis[4] == 2);
		assertTrue(dis[5] == 2);
		assertTrue(dis[6] == 0);
		assertTrue(dis[7] == 2);
		assertTrue(dis[8] == 3);
		assertTrue(dis[9] == 0);
		
		
	}
}
